﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HerGoS.Administration.Entities;
using HerGoS.Administration.Engine;
using HerGoS.ControlsUI;

namespace HerGoS.WebUI.Parametrizacion.Geografia
{
    public partial class Pais_ABM : PageBase
    {
        #region Propiedades

        public Pais Pais
        {
            get
            {
                if (ViewState["Pais"] != null)
                    return (Pais)ViewState["Pais"];
                return null;
            }
            set
            {
                ViewState["Pais"] = value;
            }

        }

     

        #endregion
         
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                 

                if (Request.QueryString["id"] == null)
                {
                    Pais = new Pais();
                }
                else
                {
                    var Id = Convert.ToInt32(Request.QueryString["id"]);
                    Pais = GestorPaises.Obtener(Id);
                    this.txtCodigo.Text = Pais.Codigo;
                    this.txtNombre.Text = Pais.Nombre;
                    this.txtNumero.Text = Pais.Numero.ToString();
               
                }
                Initialize();
            }
        }
         
         void Initialize()
         {
            this.btnGuardar.Settings(new ButtonExtText());
            this.btnCerrar.Settings(new ButtonExtText());
            
            LoadAutoria(Pais);
          }

         protected void btnGuardar_Click(object sender, EventArgs e)
         {
             Pais.Codigo = this.txtCodigo.Text;
             Pais.Nombre = this.txtNombre.Text;
             Pais.Numero = this.txtNumero.Text.ToInteger();
           
             GestorPaises.Guardar(Pais);

             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "closedialog", "parent.IntervaloCerrarPopup(' El pais ha sido guardado correctamente ','ContentPlaceHolder1_btnRefrescarPais');", true);

         }


         protected void btnCerrar_Click(object sender, EventArgs e)
         {
             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "closedialog", "parent.CerrarPopup();", true);
         }


        }
 }
